/************************************************************
* @file   wkio_regs.h
************************************************************/

#ifndef WKIO_REGS_H
#define WKIO_REGS_H

#include "gkt_types.h"

#define WKIO_CONTROL	0x40
#define WKIO_INT_STATUS	0x50
#define WKIO_INT_ENABLE	0x54
#define WKIO_INT_MASK	0x58
#define WKIO_INT_CLEAR	0x5C

#define WKIO_DET_EN_SHIFT	0
#define WKIO_DET_POL_SHIFT	1

#define wkio_detect_shift(pin, item)	\
	(((pin) << 2) + WKIO_DET_##item##_SHIFT)

#define wkio_detect_config_polarity(base_addr, pin, polarity)	\
	do {	\
		uint32_t __shift, __reg_value;	\
		__shift = wkio_detect_shift(pin, POL);	\
		__reg_value = gkt_read_reg32(base_addr + WKIO_CONTROL);	\
		__reg_value &= ~(1 << __shift);	\
		__reg_value |= polarity << __shift;	\
		gkt_write_reg32(base_addr + WKIO_CONTROL, __reg_value);	\
	} while(0)
#define wkio_detect_enable(base_addr, pin)	\
	do {	\
		uint32_t __shift, __reg_value;	\
		__shift = wkio_detect_shift(pin, EN);	\
		__reg_value = gkt_read_reg32(base_addr + WKIO_CONTROL);	\
		__reg_value |= 1 << __shift;	\
		gkt_write_reg32(base_addr + WKIO_CONTROL, __reg_value);	\
	} while(0)
#define wkio_detect_disable(base_addr, pin)	\
	do {	\
		uint32_t __shift, __reg_value;	\
		__shift = wkio_detect_shift(pin, EN);	\
		__reg_value = gkt_read_reg32(base_addr + WKIO_CONTROL);	\
		__reg_value &= ~(1 << __shift);	\
		gkt_write_reg32(base_addr + WKIO_CONTROL, __reg_value);	\
	} while(0)

#define wkio_int_get_status(base_addr)	\
	gkt_read_reg32(base_addr + WKIO_INT_STATUS)

#define wkio_int_enable(base_addr, pin)	\
	do {	\
		uint32_t __reg_value;	\
		__reg_value = gkt_read_reg32(base_addr + WKIO_INT_ENABLE);	\
		__reg_value |= 1U << pin;	\
		gkt_write_reg32(base_addr + WKIO_INT_ENABLE, __reg_value);	\
	} while(0)
#define wkio_int_disable(base_addr, pin)	\
	do {	\
		uint32_t __reg_value;	\
		__reg_value = gkt_read_reg32(base_addr + WKIO_INT_ENABLE);	\
		__reg_value &= ~(1U << pin);	\
		gkt_write_reg32(base_addr + WKIO_INT_ENABLE, __reg_value);	\
	} while(0)

#define wkio_int_mask(base_addr, pin)	\
	do {	\
		uint32_t __reg_value;	\
		__reg_value = gkt_read_reg32(base_addr + WKIO_INT_MASK);	\
		__reg_value &= ~(1U << pin);	\
		gkt_write_reg32(base_addr + WKIO_INT_MASK, __reg_value);	\
	} while(0)
#define wkio_int_unmask(base_addr, pin)	\
	do {	\
		uint32_t __reg_value;	\
		__reg_value = gkt_read_reg32(base_addr + WKIO_INT_MASK);	\
		__reg_value &= ~(1U << pin);	\
		gkt_write_reg32(base_addr + WKIO_INT_MASK, __reg_value);	\
	} while(0)

#define wkio_int_clear(base_addr, pin)	\
	do {	\
		gkt_write_reg32(base_addr + WKIO_INT_CLEAR, 1U << pin);	\
	} while(0)

#endif	/* WKIO_REGS_H */
